package jxls;

import org.jxls.common.Context;
import org.jxls.util.JxlsHelper;

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * Created by User on 2017/10/28.
 */
public class Test {

    public static void main(String[] args) {

        List employees = new ArrayList<>();
        Employee employee1 = new Employee();
        employee1.setName("阿萨德").setBirthDate(new Date()).setPayment(new BigDecimal(2000)).setBonus(new BigDecimal(100));

        Employee employee2 = new Employee();
        employee2.setName("权威").setBirthDate(new Date()).setPayment(new BigDecimal(3000)).setBonus(new BigDecimal(200));

        Employee employee3 = new Employee();
        employee3.setName("自行车").setBirthDate(new Date()).setPayment(new BigDecimal(4000)).setBonus(new BigDecimal(300));

        Employee employee4 = new Employee();
        employee4.setName("任天野").setBirthDate(new Date()).setPayment(new BigDecimal(5000)).setBonus(new BigDecimal(400));

        employees.add(employee1);
        employees.add(employee2);
        employees.add(employee3);
        employees.add(employee4);


        try(InputStream is = Test.class.getClassLoader().getResourceAsStream("object_collection_template.xls")) {
            try (OutputStream os = new FileOutputStream("target/object_collection_output.xls")) {
                Context context = new Context();
                context.putVar("employees", employees);
                JxlsHelper.getInstance().processTemplate(is, os, context);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }


    }


}
